-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimize bundled translations #1775
Conversation
Why does the forms-app bundle size reduce more than the l10n.js file size? Is the same l10n.js file packed into the bundle multiple times? |
Yep, we currently import the components as single components (instead of nc/vue as a whole). And each component contains the l10n-file. You can see this also in the two bundle-analyzer-images. |
Hm, I thought (or maybe more like hoped) that this would be optimized by webpack. |
I guess we have some improvements to do in our webpack config 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment
12984fc
to
0f82fe5
Compare
By the way, the font files also get duplicated in the final bundle. I had a look around, but couldn't find any solution for deduplicating this. If anyone has an idea, it would be great, since duplicating l10n.js and the fonts really has a huge impact on the bundle size. @nextcloud/javascript |
Moving to webbpack5 might be a great thing to do and have better tree-shaking. |
Not sure. In one of my apps I have webpack 5.27.1 and the code is still present multiple times in the final bundle. But I will check if using webpack5 in the vue-components as well has any influence. |
As far as I see, webpack sees the components from the outside as one single block. So i think having separate chunks for l10n and fonts should enable webpack to see it as separate requirement and therefore enable to import it only once... I also tried that, but didn't manage to import it on a quick-shot. Seems to need some specific handling on the apps (or components?) to import the chunk then. EDIT: Btw. also nice would be if we manage to import the chunk conditionally then. So as password_policy does not use the info-icon of settingsSection, the iconfonts package could be left out completely.... 🤔 |
⬆️ Small fixup to optimize plural storing a bit. |
Opened a separate issue for deduplication, so we can keep track there. #1779 |
Signed-off-by: Jonas Rittershofer <[email protected]>
9b3f3da
to
c1e09af
Compare
Somebody else up for a second review here? 😊 |
Why?
On Password-Policy the usage of SettingsSection instead of a simple div blew up the package-size from
100 KiB
to330 KiB
of which140 KB
are thel10n.js
of vue-Components. So i thought about how to reduce this.Idea
The current implementation inserts the pot-file as json, and packs this within the bundle. However, there is a huge overhead on that kind of storing. So the idea was to reduce the overhead by storing only necessary data.
As model i initially used the json-format as translations are stored within apps.
Approach
=>
Webpack-build compresses -> Component stores compressed data -> l10n.js decompresses when loading gettext
plural-forms
,language
andcontent-type
headers.Result
This approach reduces the size of the bundled l10n.js from
142 KB
to32 KB
!Thus, the bundled password_policy settings reduce from
346 KiB
to237 KiB
, while e.g. the forms-app bundle reduces from2.75 MiB
to2.21 MiB
.More Information:
The way translations are stored currently (Only 1 plural and 2 singular translations):
The way i would store it here (same translation Data!):
Colorful image of the bundles before:
Colorful image of the bundles after: